<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>编辑交易</title>
  <meta name="renderer" content="webkit">
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  
    {include file="public/css"}
    {include file="public/js"}
</head>
<body>
<!-- 后台面包屑导航 -->
{:get_admin_breadcrumb()}
<blockquote class="layui-elem-quote" style="margin-top:10px;">说明：编辑交易</blockquote>

<div class=""  style="padding:20px">

   
<form class="layui-form" action="" method="post" >
<input type="hidden" name="id" value="{$Request.param.id}">
               <div class="layui-form-item">
                <label class="layui-form-label" style="width:100px;"> 交易分类</label>   
            
                 {:get_cate('guarantee_category',$guaranteeinfo.cid)} 
                 
              </div>

              <div class="layui-form-item">
                <label class="layui-form-label" style="width:100px;"> 交易标题</label>
                <div class="layui-input-inline" style="width:500px">
                  <input type="text" name="title" lay-verify="title" autocomplete="off" placeholder="" class="layui-input"  value="{$guaranteeinfo.title}" >
                </div>
                 <div class="layui-form-mid layui-word-aux"><span class="orange">*</span> 必填</div>
              </div>

              <div class="layui-form-item">
                <label class="layui-form-label" style="width:100px;"> 发布用户 </label>
                <div class="layui-input-inline">
                  <input type="text" name="username" lay-verify="username" autocomplete="off" placeholder="" class="layui-input" value="{$guaranteeinfo.username}" id="username">
                </div>
                  <div class="layui-input-inline">
                   <a href="javascript:;"  class="layui-btn layui-btn layui-btn-normal" id="choose-user">选择用户</a>
                 </div>
                 <div class="layui-form-mid layui-word-aux">{:about('必须是本站用户')}</div>
              </div>

              <div class="layui-form-item">
                <label class="layui-form-label" style="width:100px;"> 发布者身份 </label>
                <div class="layui-input-block" >
                <input type="radio" name="id_type" lay-filter="id_type" value="0" title="买家" {if $guaranteeinfo.id_type ==0} checked {/if}>
                <input type="radio" name="id_type" lay-filter="id_type" value="1"  title="卖家" {if $guaranteeinfo.id_type ==1} checked {/if>
           
                </div>
                 <div class="layui-form-mid layui-word-aux"></div>
              </div>
              <div class="layui-form-item">
                <label class="layui-form-label" style="width:100px;"> 交易价格</label>
                <div class="layui-input-inline" style="width:150px;">
                  <input type="text" name="price" id="price" lay-verify="price" autocomplete="off" placeholder="" class="layui-input" maxlength="10" value="{$guaranteeinfo.price}" >
                </div>
                 <div class="layui-form-mid layui-word-aux">元</div>
              </div>

              <div class="layui-form-item">
                <label class="layui-form-label" style="width:100px;"> 中介费 </label>
                <div class="layui-input-block" >
                <input type="radio" name="fee_type" lay-filter="fee_type" value="1" title="买家全付 " {if $guaranteeinfo.fee_type ==1} checked {/if} >
                <input type="radio" name="fee_type" lay-filter="fee_type" value="2"  title="卖家全付 " {if $guaranteeinfo.fee_type ==2} checked {/if}>
                <input type="radio" name="fee_type" lay-filter="fee_type" value="3" title="双方各付一半" {if $guaranteeinfo.fee_type ==3} checked {/if} >
                </div>
                 <div class="layui-form-mid layui-word-aux"></div>
              </div>
             <div class="layui-form-item">
                <label class="layui-form-label" style="width:100px;">状态</label>
                <div class="layui-input-inline">
                 <div class="layui-form-mid layui-word-aux">
                 {if $guaranteeinfo.status ==0}
                   <span class="layui-badge layui-bg-gray">待审核</span>
                 {elseif $guaranteeinfo.status ==1}
                  <span class="layui-badge layui-bg-gray">待交易</span>
                 {elseif $guaranteeinfo.status ==2}
                   <span class="layui-badge layui-bg-blue">交易中</span>
                  {elseif $guaranteeinfo.status ==3}
                  <span class="layui-badge layui-bg-blue">交易成功</span>
                  {elseif $guaranteeinfo.status ==4}
                  <span class="layui-badge layui-bg-orange">交易关闭</span>
                 {elseif $guaranteeinfo.status ==-1}
                  <span class="layui-badge layui-bg-orange">审核失败</span>
                {/if}
                </div>
                </div>
              </div>

              <div class="layui-form-item">
                <label class="layui-form-label" style="width:100px;"> 担保内容</label>
                <div class="layui-input-block" style="padding:8px">
                 {form:ueditor name="content" value="htmlspecialchars_decode($guaranteeinfo['content'])"}
                </div>
              </div>
              {if $guaranteeinfo.status ==0}
                <div class="layui-form-item">
                <label class="layui-form-label" style="width:100px;">审核状态</label>
                <div class="layui-input-block">
                <input type="radio" name="status"  value="0" {if $guaranteeinfo.status ==0} checked {/if} title="待审">
                <input type="radio" name="status"  value="1" {if $guaranteeinfo.status ==1} checked {/if} title="通过">
                <input type="radio" name="status"  value="2"  {if $guaranteeinfo.status ==2} checked {/if} title="拒绝" >
                </div>
              </div>
               {/if}

{if !empty($guaranteeinfo.order)}          
已成交订单
<hr>

 <div class="layui-form-item">
    <label class="layui-form-label" style="width:100px;">订单编号</label>
    <div class="layui-input-inline" >
      <div class="layui-form-mid layui-word-aux">{$guaranteeinfo.order.id}</div>
    </div>
  </div>
              <div class="layui-form-item">
                <label class="layui-form-label" style="width:100px;"> 实际结算 </label>    
                <div class="layui-form-mid layui-word-aux" id="result" style="">
                买家支付 <span class="orange">{$guaranteeinfo.order.buyer_pay} </span> 元 卖家获得 <span class="orange">{$guaranteeinfo.order.seller_get} </span> 元</div>
              </div>
 <div class="layui-form-item">
                <label class="layui-form-label" style="width:100px;"> 买家 </label>
                <div class="layui-input-inline">
                    <div class="layui-form-mid layui-word-aux">{$guaranteeinfo.order.buyer}</div>
                </div>
                 
              </div>
 <div class="layui-form-item">
                <label class="layui-form-label" style="width:100px;"> 卖家 </label>
                <div class="layui-input-inline">
                    <div class="layui-form-mid layui-word-aux">{$guaranteeinfo.order.seller}</div>
                </div>
              </div>
 <div class="layui-form-item">
                <label class="layui-form-label" style="width:100px;"> 支付时间 </label>
                <div class="layui-input-inline">
                    <div class="layui-form-mid layui-word-aux">{$guaranteeinfo.order.pay_time|date="Y-m-d"}</div>
                </div>
              </div>
 <div class="layui-form-item">
                <label class="layui-form-label" style="width:100px;"> 订单状态 </label>
                <div class="layui-input-inline">
                    <div class="layui-form-mid layui-word-aux">{$guaranteeinfo.order.pay_time|date="Y-m-d"}</div>
                </div>
              </div>
    
{/if}
              <div class="layui-form-item">
                <label class="layui-form-label" style="width:100px;"></label>
                <div class="layui-input-inline">
                   <button class="layui-btn layui-btn-normal"  lay-submit lay-filter="form">确 定</button>
                    <button class="layui-btn layui-btn-primary"  onclick="back()">返 回</button>
                </div>
              </div>


</form>
</div>

<script>
layui.use(['element', 'layer','form','upload'], function(){
   var  element = layui.element, layer = layui.layer,form = layui.form;;upload = layui.upload;
 
// 中介交易 
 $('#price').on('keyup',function(){
     money();
 });

 form.on("radio(free_type)",function(){
    money();
 });
function money()
{
      var fee_type = $("input[name='free_type']:checked").val();
      if(fee_type <0){
        layer.msg('请选择中介费支付方式');
        return false;
      }
       var price = $("#price").val(); //价格
       var free_ratio = "{$settings.guarantee.free_ratio}"; //手续费比例
      if(free_ratio <= 0){
        free_ratio = 0;
      }
      price =  parseInt(price);
      free_ratio =  parseInt(free_ratio);
       if(price > 0 ){
          var free =  price * (free_ratio/100);
          if(fee_type ==1){
       
            var buyer = '买家支付 <span class="orange">'+ (price+free)+'</span> 元';
            var seller= '卖家获得 <span class="orange">'+ price+'</span> 元';
            $("#buyer_pay").val(price+free);
            $("#seller_get").val(price);
            $("#result").html(buyer+' '+seller);
          }else if(fee_type ==2){
            var buyer = '买家支付 <span class="orange">'+ (price)+'</span> 元';
            var seller= '卖家获得 <span class="orange">'+ (price-free)+'</span> 元';
            $("#buyer_pay").val(price);
            $("#seller_get").val(price-free);
            $("#result").html(buyer+' '+seller);
          }else if(fee_type ==3){
            var buyer = '买家支付 <span class="orange">'+ (price+free/2)+'</span> 元';
            var seller= '卖家获得 <span class="orange">'+ (price-free/2)+'</span>元';
            $("#buyer_pay").val(price-free/2);
            $("#seller_get").val(price-free/2);
            $("#result").html(buyer+' '+seller);
          }
         
       }else{
          $("#result").html('<span class="orange">交易价格不能为空</span>');
       }
}



 //监听提交
  form.on('submit(form)', function(data){
    $.post("{:url('guarantee/infoEdit')}",$("form").serialize(),function(json){
      if(json.code == 0){
        qilecms.success(json.msg);
        setTimeout(function(){
         qilecms.back();
        },1000);
        }else{
          qilecms.error(json.msg);
        }
    });
     return false;
  });

//选择发布用户
$("#choose-user").on('click',function(){
  layer.open({
    type: 2,
    title:'选择卖家',
    shadeClose:true,
    shade: 0.4,
    area: ['650px','90%'],
    maxmin: true, //
    resize:false,
    content: '{:url("user/userSelect")}',
    success: function(layero, index){ 
    var id ='username';
    var body = layer.getChildFrame('body', index);
    body.find('#chooseType').val(id); //找到子iframe 中的dom 元素，传值过去
    }
  }); 
});
});

</script>
<script>

</script>
</body>

</html>